package echartstest;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map.Entry;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class maptest extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public maptest() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		JSONArray datas=new JSONArray();
//		JSONObject data1=new JSONObject();
//		JSONArray geocoord=new JSONArray();
//		geocoord.add(121.48);
//		geocoord.add(31.22);
//		data1.put("name", "上海");
//		data1.put("value",90);
//		data1.put("geoCoord", JSONArray.parse(GeoCoord.map.get("上海")));
//		datas.add(data1);
//		JSONObject data2=new JSONObject();
//		data2.put("name", "北京");
//		data2.put("value",90);
//		data2.put("geoCoord", JSONArray.parse(GeoCoord.map.get("北京")));
//		datas.add(data2);
		Iterator<Entry<String, JSONArray>> iter=GeoCoord.map.entrySet().iterator();
		while(iter.hasNext())
		{
			Entry<String, JSONArray> entry = iter.next();
			JSONObject data=new JSONObject();
			data.put("name", entry.getKey());
			data.put("value",90);
			data.put("geoCoord", entry.getValue());
			datas.add(data);
		}
		out.print(datas.toJSONString());
		
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
